package com.my.user.config;

import com.alibaba.dubbo.config.*;
import com.my.common.service.UserService;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.Arrays;

//相当于spring的dubbo xml配置，每个@Bean对应一个dubbo:标签，写法比较繁琐，了解
//@Configuration
public class MyDubboConfig {

    @Bean //<dubbo:application>
    public ApplicationConfig application(){
        ApplicationConfig application = new ApplicationConfig();
        application.setName("user-service-provider-springboot");
        return application;
    }

    @Bean //<dubbo:registry>
    public RegistryConfig registry(){
        RegistryConfig registry = new RegistryConfig();
        registry.setProtocol("zookeeper");
        registry.setAddress("127.0.0.1:2181");
        return registry;
    }

    @Bean //<dubbo:protocol>
    public ProtocolConfig protocol(){
        ProtocolConfig protocol = new ProtocolConfig();
        protocol.setName("dubbo");
        protocol.setPort(20882);
        return protocol;
    }

    @Bean //<dubbo:service>
    public ServiceConfig<UserService> service(UserService userServiceImpl2){
        ServiceConfig<UserService> service = new ServiceConfig<>();
        service.setInterface(UserService.class);
        service.setRef(userServiceImpl2);
        service.setTimeout(2000);
        //<dubbo:method>
        MethodConfig method = new MethodConfig();
        method.setName("getList");
        method.setTimeout(1000);
        service.setMethods(Arrays.asList(method));
        return service;
    }
}
